package org.jypj.dev.service.impl;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;

import org.jypj.dev.util.StringUtil;
import org.springframework.stereotype.Service;
import org.jypj.dev.model.ThingUseRecord;
import org.jypj.dev.dao.IThingUseRecordDao;
import org.jypj.dev.service.IThingUseRecordService;
import org.jypj.dev.util.Page;
import org.jypj.dev.util.Page;

@Service("thingUseRecordService")
public class ThingUseRecordServiceImpl implements IThingUseRecordService {
	
    @Resource 
    private IThingUseRecordDao thingUseRecordDao;
    
    /**
	 * 保存    
	 * 字段为空的不存防止覆盖存在默认值的字段
	 * @param thingUseRecord
	 * @return 保存后的对象包括ID
	 */	
	public int saveThingUseRecordByField(ThingUseRecord thingUseRecord){
		if(StringUtil.isEmpty(thingUseRecord.getId())){
			String uuid =UUID.randomUUID().toString().replace("-", "").trim();
			thingUseRecord.setId(uuid);
		}
		return thingUseRecordDao.saveThingUseRecordByField(thingUseRecord);
	}
	
	/**
	 * 保存    
	 * 所有字段全都保存
	 * @param thingUseRecord 
	 * @return 保存后的对象包括ID
	 */	
	public int saveThingUseRecord(ThingUseRecord thingUseRecord){
		if(StringUtil.isEmpty(thingUseRecord.getId())){
			String uuid =UUID.randomUUID().toString().replace("-", "").trim();
			thingUseRecord.setId(uuid);
		}
		return thingUseRecordDao.saveThingUseRecord(thingUseRecord);
	}
    
    /**
	 * 根据ID删除
	 * @param id 主键ID
	 * @return 删除记录数
	 */	
    public int deleteThingUseRecordById(String id){
    
    	return thingUseRecordDao.deleteThingUseRecordById(id);
    }
    
   	/**
	 * 根据对象删除
	 * @param id 主键ID
	 * @return 
	 */	
    public int deleteThingUseRecordByObject(ThingUseRecord thingUseRecord){
    
    	return thingUseRecordDao.deleteThingUseRecordByObject(thingUseRecord);
    }
    /**
	 * 更新  
	 * 只更新值不为空的字段
	 * @param thingUseRecord 
	 * @return 保存后的对象包括ID
	 */	
    public int updateThingUseRecordByField(ThingUseRecord thingUseRecord){
    
    	return thingUseRecordDao.updateThingUseRecordByField(thingUseRecord);
    }
    
    /**
	 * 更新  
	 * 更新所有字段
	 * @param thingUseRecord 
	 * @return 保存后的对象包括ID
	 */	
    public int updateThingUseRecord(ThingUseRecord thingUseRecord){
    
    	return thingUseRecordDao.updateThingUseRecord(thingUseRecord);
    }
    
   /**
	 * 按ID查询
	 * @parm id 主键ID
	 * @return ThingUseRecord 
	 */	
    public ThingUseRecord selectThingUseRecordById(String id){
    
    	return thingUseRecordDao.selectThingUseRecordById(id);
    }
    
    /**
	 * 分页查询 包含条件
	 * @param page 分页对象
	 * @param map  查询条件  
	 * @return  List<ThingUseRecord>
	 */	
     public Page selectOnePageByMap(Page page,Map<String,Object> map){
     	 List<ThingUseRecord> thingUseRecords =thingUseRecordDao.selectOnePageByMap(page,map);
	     	if(thingUseRecords!=null&&thingUseRecords.size()>0){
	     		page.setResult(thingUseRecords);
	     	}else{
	     		page.setResult(new ArrayList<ThingUseRecord>());
	     	}
	     	return page;
     }
    /**
	 * 分页查询 包含对象条件
	 * @param page 分页对象
	 * @param thingUseRecord  查询条件  
	 * @return Page
	 */	
     public Page selectOnePageByThingUseRecord(Page page,ThingUseRecord thingUseRecord){
 		 List<ThingUseRecord> thingUseRecords =thingUseRecordDao.selectOnePageByThingUseRecord(page,thingUseRecord);
	     	if(thingUseRecords!=null&&thingUseRecords.size()>0){
	     		page.setResult(thingUseRecords);
	     	}else{
	     		page.setResult(new ArrayList<ThingUseRecord>());
	     	}
	     	return page;
     }
    
   /**
	 * 按条件查询全部的
	 * @param map  查询条件  
	 * @return  List<ThingUseRecord>
	 */	
     public List<ThingUseRecord> selectAllByMap(Map<String,Object> map){
     	return thingUseRecordDao.selectAllByMap(map);
     }
     
      
   /**
	 * 按条件查询全部的
	 * @param map  查询条件  
	 * @return  List<ThingUseRecord>
	 */	
     public List<ThingUseRecord> selectAllByThingUseRecord(ThingUseRecord thingUseRecord){
     
    	 return thingUseRecordDao.selectAllByThingUseRecord(thingUseRecord);
     }
		
		/**
	 * 按条件查询单个对象
	 * @param map  查询条件  
	 * @return  ThingUseRecord
	 */	
     public ThingUseRecord selectObjectByMap(Map<String,Object> map){
     
    	 return thingUseRecordDao.selectObjectByMap(map);
     }
     
     /**
	 * 按条件查询单个对象
	 * @param map  查询条件  
	 * @return  ThingUseRecord
	 */	
     public ThingUseRecord selectObjectByThingUseRecord(ThingUseRecord thingUseRecord){
     
     	return thingUseRecordDao.selectObjectByThingUseRecord(thingUseRecord);
     }
}